package com.hhlkeepalive.onePx;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.hhlkeepalive.utils.ActivityManager;

public class KeepAliveReceiver extends BroadcastReceiver {
    private final  static String TAG="KeepAlive";
    @Override
    public void onReceive(Context context, Intent intent) {
        String action=intent.getAction();
        if(action.equals(Intent.ACTION_SCREEN_OFF)){
            Log.e(TAG,"KeepAliveReceiver--->关闭屏幕");
            Activity activity = ActivityManager.getCurrRunActivity().getActivity();
            activity.startActivity(new Intent(activity,OnePxActivity.class));
        }else if(action.equals(Intent.ACTION_SCREEN_ON)){
            Log.e(TAG,"KeepAliveReceiver--->打开屏幕"+"--->"+ActivityManager.getCurrActivity());
            ActivityManager.destroyActivity("com.hhlkeepalive.onePx.OnePxActivity");

        }
    }
}
